package com.cgwx.service.impl;

import com.cgwx.entity.UsUser;
import com.cgwx.mapper.UserMapper;
import com.cgwx.service.IUserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Resource
    private UserMapper userMapper;

    public List<UsUser> getAllUser(){
        return userMapper.getAllUser();
    }

    @Override
    public List<UsUser> getUser(UsUser user) {
        return userMapper.getUser(user);
    }

    @Override
    public String getDeptIdByAccount(String account) {
        UsUser user = new UsUser();
        user.setAccount(account);
        return getUser(user).get(0).getDeptId();
    }

    @Override
    public List<String> getRolesByAccount(String account) {
        String roleIds = userMapper.getRoleIdByUser(account);
        String[] roleIdList = roleIds.split(",");
        List<String> roleList = new ArrayList<>();
        for(String roleId : roleIdList) roleList.add(userMapper.getRolesByUser(roleId));
        return roleList;
    }
}

